package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.domain.entity.SysSetting;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.utils.orm.WrapperTool;
import com.jvyou.app.ds.domain.dto.SysSettingDto;
import com.jvyou.app.ds.mapper.SysSettingMapper;
import com.jvyou.app.ds.service.SysSettingService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 系统设置表(SysSetting)表服务实现类
 *
 * @author 橘柚
 * @since 2025-03-24 10:02:50
 */
@Service("sysSettingService")
public class SysSettingServiceImpl extends ServiceImpl<SysSettingMapper, SysSetting> implements SysSettingService {

    private QueryWrapper<SysSetting> getWrapper(SysSettingDto sysSettingDto) {
        QueryWrapper<SysSetting> queryWrapper = new QueryWrapper<>();
        WrapperTool.notEmptyEq(queryWrapper, "setting_key", sysSettingDto.getSettingKey());
        WrapperTool.notEmptyLike(queryWrapper, "name", sysSettingDto.getName());
        WrapperTool.notEmptyEq(queryWrapper, "setting_type", sysSettingDto.getSettingType());
        return queryWrapper;
    }

    @Override
    public List<SysSetting> listSysSetting(SysSettingDto sysSettingDto) {
        return list(getWrapper(sysSettingDto));
    }

    @Override
    public PageResult<SysSetting> pageSysSetting(SysSettingDto sysSettingDto) {
        IPage<SysSetting> page = new Page<>(sysSettingDto.getCurrent(), sysSettingDto.getPageSize());
        return PageResult.success(page(page, getWrapper(sysSettingDto)));
    }
}
